/*
 * Copyright (c) 2011-2013, fortiss GmbH.
 * Licensed under the Apache License, Version 2.0.
 *
 * Use, modification and distribution are subject to the terms specified
 * in the accompanying license file LICENSE.txt located at the root directory
 * of this software distribution. A copy is available at
 * http://chromosome.fortiss.org/.
 *
 * This file is part of CHROMOSOME.
 *
 * $Id: udpSend.h 6003 2013-12-05 12:59:15Z wiesmueller $
 */

/**
 * \file
 *
 * \brief  Waypoint that copies the data on UDP network transportation.
 *
 * \author
 *         This file has been generated by the CHROMOSOME Modeling Tool (fortiss GmbH).
 */

#ifndef XME_WP_UDP_UDPSEND_H
#define XME_WP_UDP_UDPSEND_H

/**
 * \addtogroup wp_udp
 * @{
 */

/******************************************************************************/
/***   Includes                                                             ***/
/******************************************************************************/
#include "xme/core/component.h"
#include "xme/core/dataManagerTypes.h"

#include "xme/hal/include/net.h"

#include "xme/wp/waypoint.h"

#include <stdint.h>

/******************************************************************************/
/***   Prototypes                                                           ***/
/******************************************************************************/
XME_EXTERN_C_BEGIN

/**
 * \brief  Initialize this waypoint.
 *
 * \retval XME_STATUS_SUCCESS if the waypoint has been initialized successfully.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred.
 */
xme_status_t
xme_wp_udp_udpSend_init(void);

/**
 * \brief  Execute this waypoint.
 *
 * \details Before calling this, you must once add a configuration for the given
 *         instanceId, via xme_wp_udp_udpSend_addConfig.
 *         Executing this function will get the topic data from the inputPort
 *         of the associated configuration and output it on the network. 
 *         The required network configuration is chosen from the input parameter
 *
 * \param[in]  instanceId Id of the configuration for which to execute the waypoint, as returned by
 *         xme_wp_udpSend_addConfig.
 *
 * \retval XME_STATUS_SUCCESS
 * \retval XME_STATUS_INVALID_HANDLE if no configuration has been added for
 *         the given instanceId.
 * \retval XME_STATUS_INTERNAL_ERROR if there was an error reading from the
 *         input port or writing to the network
 */
xme_status_t
xme_wp_udp_udpSend_run
(
    xme_wp_waypoint_instanceId_t instanceId
);

/**
 * \brief  Check if the given configuration exists for this waypoint.
 *
 * \param[in]  instanceId Pointer where id for the already existing config
 *         Only valid when XME_STATUS_SUCCESS has been returned.
 * \param[in]  dataId     Pointer to data packet id which is used in the existsing config
 *         Only valid when XME_STATUS_SUCCESS has been returned.
 * \param[in]  key        The key to correctly identify the intended receipent.
 * \param[in]  hostname   hostname of the desination system
 * \param[in]  port       port at which communication is to be sent.
 *
 * \retval XME_STATUS_SUCCESS if the configuration exists.
 * \retval XME_STATUS_NOT_FOUND if the configuration does not exists.
 */
xme_status_t
xme_wp_udp_udpSend_getConfig
(
    xme_wp_waypoint_instanceId_t* instanceId,
    xme_core_dataManager_dataPacketId_t* dataId,
    const void *key,
    const char* hostname,
    uint16_t port
);

/**
 * \brief Add a new configuration for this waypoint.
 *
 * \param[in] instanceId Pointer where id for the newly added configuration is written to
 *        Only valid when XME_CORE_STATUS_SUCCESS has been returned.
 * \param[in] dataId Input data port.
 * \param[in] topic Topic associated to this configuration.
 * \param[in] sizeOfData Size of the topic data which will appear at the data port (attributes not considered).
 * \param[in] buffer Buffer space to be used to construct the network packets
 * \param[in] sizeOfBuffer Size of the buffer.
 * \param[in] key The key to correctly identify the intended receipent.
 * \param[in] hostname Hostname of the destination system.
 * \param[in] port Port at which communication is to be opened at the hostname.
 * \param[in] isBroadcast If this port is for broadcast.
 *
 * \retval XME_STATUS_SUCCESS if the configuration has been added successfully.
 * \retval XME_STATUS_OUT_OF_RESOURCES if the configuration could not be added due
 *         to resource constraints (e.g. not enough memory to store entry).
 */
xme_status_t
xme_wp_udp_udpSend_addConfig
(
    xme_wp_waypoint_instanceId_t* instanceId,
    xme_core_dataManager_dataPacketId_t dataId,
    xme_core_topic_t topic,
    uint16_t sizeOfData,
    void *buffer,
    uint16_t sizeOfBuffer,
    const void *key,
    const char* hostname,
    uint16_t port,
    bool isBroadcast
);

/**
 * \brief Removes a configuration of this waypoint.
 *
 * \param[in] instanceId InstanceID of the configuration which has to be removed.
 *
 * \retval XME_STATUS_SUCCESS if configuration was successfully removed.
 * \retval XME_STATUS_INVALID_HANDLE if the given instanceID was invalid.
 */
xme_status_t
xme_wp_udp_udpSend_removeConfig
(
    xme_wp_waypoint_instanceId_t instanceId
);

/**
 * \brief  Finalize this waypoint.
 *
 * \retval XME_STATUS_SUCCESS if the waypoint has been finalized successfully.
 * \retval XME_STATUS_INTERNAL_ERROR if an error occurred.
 */
xme_status_t
xme_wp_udp_udpSend_fini(void);

/**
 * \brief  Calculates package over head required for header
 *
 * \return Number of bytes required to store the header.
 */
uint16_t
xme_wp_udp_udpSend_getPackageOverHead(void);

XME_EXTERN_C_END

/**@}*/

#endif // #ifndef XME_WP_UDP_UDPSEND_H
